<template>
  <el-menu
      :mode="direction"
      :default-active="activeIndex"
      class="el-menu-demo"
      :ellipsis="direction === 'horizontal'"
      :unique-opened="direction === 'vertical'"
      :popper-offset="16"
      style="max-width: 600px"
      @select="handleSelect"
  >
    <el-menu-item index="0" @click="toggleDirection">
      <svg-icon name="login-logo" size="30"></svg-icon>
      <span>龙茶清欢</span>
    </el-menu-item>

    <el-sub-menu index="1">
      <template #title>
        <el-icon><message /></el-icon>Navigator One
      </template>
      <el-menu-item-group>
        <template #title>Group 1</template>
        <el-menu-item index="1-1">Option 1</el-menu-item>
        <el-menu-item index="1-2">Option 2</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="Group 2">
        <el-menu-item index="1-3">Option 3</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="1-4">
        <template #title>Option4</template>
        <el-menu-item index="1-4-1">Option 4-1</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>
    <el-sub-menu index="2">
      <template #title>
        <el-icon><icon-menu /></el-icon>Navigator Two
      </template>
      <el-menu-item-group>
        <template #title>Group 1</template>
        <el-menu-item index="2-1">Option 1</el-menu-item>
        <el-menu-item index="2-2">Option 2</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="Group 2">
        <el-menu-item index="2-3">Option 3</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="2-4">
        <template #title>Option 4</template>
        <el-menu-item index="2-4-1">Option 4-1</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>
    <el-sub-menu index="3">
      <template #title>
        <el-icon><setting /></el-icon>Navigator Three
      </template>
      <el-menu-item-group>
        <template #title>Group 1</template>
        <el-menu-item index="3-1">Option 1</el-menu-item>
        <el-menu-item index="3-2">Option 2</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="Group 2">
        <el-menu-item index="3-3">Option 3</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="3-4">
        <template #title>Option 4</template>
        <el-menu-item index="3-4-1">Option 4-1</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>
    <el-sub-menu index="4">
      <template #title>
        <el-icon><location /></el-icon>
        <span>Navigator One</span>
      </template>
      <el-menu-item-group title="Group One">
        <el-menu-item index="4-1">item one</el-menu-item>
        <el-menu-item index="4-2">item two</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="Group Two">
        <el-menu-item index="4-3">item three</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="4-4">
        <template #title>item four</template>
        <el-menu-item index="4-4-1">item one</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>
    <el-menu-item index="5">
      <el-icon><icon-menu /></el-icon>
      <span>Navigator Two</span>
    </el-menu-item>
    <el-menu-item index="6" disabled>
      <el-icon><document /></el-icon>
      <span>Navigator Three</span>
    </el-menu-item>
    <el-menu-item index="7">
      <el-icon><setting /></el-icon>
      <span>Navigator Four</span>
    </el-menu-item>


  </el-menu>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

// 默认为水平菜单，horizontal | vertical 前者为水平菜单，后者为垂直菜单
const direction = ref('horizontal')
const toggleDirection = () => {
  direction.value = direction.value === 'horizontal' ? 'vertical' : 'horizontal'
}

const activeIndex = ref('1')
const handleSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>

<style scoped lang="scss">
//.el-menu--horizontal > .el-menu-item:nth-child(1) {
//  margin-right: auto;
//}
</style>